﻿@page

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>WebSocket-Server</title>
    <link href="/common/common.css" rel="stylesheet" />
    <script src="/common/jquery-1.10.2.min.js"></script>
    <script src="/common/common.js"></script>
    <style>
        html {
            padding: 30px;
        }
    </style>
    <script>
        var logCount = 0;

        function log(result) {
            if (result.Code == 0)
                $("#log").val(stringFormat("({0}){1}\r\n{2}\r\n\r\n{3}", ++logCount, new Date(), result.Data.toJsonString(), $("#log").val()));
        }

        $(document).ready(function () {
            $("#startup").click(function () {
                $.postForm("api/websocketserver/startup", {
                    port: $("#port").val(),
                    route: $("#route").val()
                }, function (result) {
                    log(result);
                });
            });

            $("#stop").click(function () {
                $.postNull("api/websocketserver/stop", function (result) {
                    log(result);
                });
            });

            $("#send").click(function () {
                $.postText("api/websocketserver/send", $("#msg").val(), function (result) {
                    log(result);
                });
            });

            $.postNull("api/websocketserver/GetMsgCache", function (result) {
                if (result.Code == 0)
                    $("#msg").val(result.Data);
            });

            $.postNull("api/websocketserver/GetState", function (result) {
                log(result);
            });

            $.loop(function () {
                $.postNull("api/websocketserver/getlog", function (result) {
                    log(result);
                });
            }, 3);
        });
    </script>
</head>
<body bgcolor="#cccccc">
    <h3>WebSocket-Server</h3>
    <hr />
    端口：<input id="port" placeholder="8888" value="8401" />
    路由：<input id="route" placeholder="xxxx" value="unity" />
    <button id="startup">监听</button>
    <button id="stop">断开</button>
    <hr />
    <textarea id="msg" class="width600px height100px"></textarea>
    <button id="send">发送</button>
    <hr />
    日志：<br />
    <textarea id="log" class="width700px height300px"></textarea>
</body>
</html>